package app.itgungnir.compose.wan.api

import app.itgungnir.compose.wan.utils.Header
import com.google.gson.JsonObject
import retrofit2.http.*

interface WanApi {

    // ================================================================
    // 账号相关
    // ================================================================
    @POST(Api.Account.LOGIN)
    suspend fun login(
        @Query("username") userName: String,
        @Query("password") password: String
    ): JsonObject

    @POST(Api.Account.REGISTER)
    suspend fun register(
        @Query("username") username: String,
        @Query("password") password: String,
        @Query("repassword") repassword: String
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @GET(Api.Account.LOGOUT)
    suspend fun logout(): JsonObject

    // ================================================================
    // 积分相关
    // ================================================================
    @Headers(Header.NEED_LOGIN)
    @GET(Api.Coin.COINS)
    suspend fun getUserCoinInfo(): JsonObject

    @GET(Api.Coin.COIN_RANK)
    suspend fun getCoinRank(
        @Path("pageNo") pageNo: Int
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @GET(Api.Coin.COIN_MANIFEST)
    suspend fun getCoinManifest(
        @Path("pageNo") pageNo: Int
    ): JsonObject

    // ================================================================
    // 系统消息相关
    // ================================================================
    @Headers(Header.NEED_LOGIN)
    @GET(Api.Message.MSG_UNREAD_COUNT)
    suspend fun getUnreadMessageCount(): JsonObject

    @Headers(Header.NEED_LOGIN)
    @GET(Api.Message.UNREAD_MSG)
    suspend fun getUnreadMessageList(
        @Path("pageNo") pageNo: Int
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @GET(Api.Message.READ_MSG)
    suspend fun getReadMessageList(
        @Path("pageNo") pageNo: Int
    ): JsonObject

    // ================================================================
    // 首页相关
    // ================================================================
    @GET(Api.Home.BANNERS)
    suspend fun getBanners(): JsonObject

    @GET(Api.Home.HOT_ARTICLES)
    suspend fun getHotArticles(): JsonObject

    @GET(Api.Home.HOME_ARTICLES)
    suspend fun getHomeArticles(
        @Path("pageNo") pageNo: Int
    ): JsonObject

    // ================================================================
    // 收藏文章相关
    // ================================================================
    @Headers(Header.NEED_LOGIN)
    @POST(Api.Collection.COLLECT_ARTICLE)
    suspend fun collectArticle(
        @Path("articleId") articleId: Long
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Collection.UNCOLLECT_ARTICLE)
    suspend fun uncollectArticle(
        @Path("articleId") articleId: Long
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @GET(Api.Collection.MY_COLLECTIONS)
    suspend fun getMyCollections(
        @Path("pageNo") pageNo: Int
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Collection.ADD_COLLECTION)
    suspend fun addCollection(
        @Query("title") title: String,
        @Query("link") link: String,
        @Query("author") author: String
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Collection.UPDATE_COLLECTION)
    suspend fun updateCollection(
        @Path("articleId") articleId: Long,
        @Query("title") title: String,
        @Query("link") link: String,
        @Query("author") author: String
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Collection.DELETE_COLLECTION)
    suspend fun deleteCollection(
        @Path("articleId") articleId: Long,
        @Query("originId") originId: Long
    ): JsonObject

    // ================================================================
    // 常用网站相关
    // ================================================================
    @Headers(Header.NEED_LOGIN)
    @GET(Api.Website.MY_WEBSITES)
    suspend fun getMyWebsites(): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Website.ADD_WEBSITE)
    suspend fun addWebsite(
        @Query("name") name: String,
        @Query("link") link: String
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Website.UPDATE_WEBSITE)
    suspend fun updateWebsite(
        @Query("id") id: Long,
        @Query("name") name: String,
        @Query("link") link: String
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Website.DELETE_WEBSITE)
    suspend fun deleteWebsite(
        @Query("id") id: Long
    ): JsonObject

    // ================================================================
    // 待办相关
    // ================================================================
    @Headers(Header.NEED_LOGIN)
    @POST(Api.Agenda.ADD_AGENDA)
    suspend fun addAgenda(
        @Query("title") title: String,
        @Query("content") content: String,
        @Query("date") date: String? = null,
        @Query("type") type: Int?,
        @Query("priority") priority: Int?
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Agenda.AGENDA_LIST)
    suspend fun getAgendaList(
        @Path("pageNo") pageNo: Int,
        @Query("status") status: Int? = null,
        @Query("type") type: Int? = null,
        @Query("priority") priority: Int? = null,
        @Query("orderby") orderby: Int? = 4
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Agenda.UPDATE_AGENDA)
    suspend fun updateAgenda(
        @Path("agendaId") agendaId: Long,
        @Query("title") title: String? = null,
        @Query("content") content: String? = null,
        @Query("date") date: String? = null,
        @Query("status") status: Int,
        @Query("type") type: Int,
        @Query("priority") priority: Int
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Agenda.UPDATE_AGENDA_STATUS)
    suspend fun updateAgendaStatus(
        @Path("agendaId") agendaId: Long,
        @Query("status") status: Int
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Agenda.DELETE_AGENDA)
    suspend fun deleteAgenda(
        @Path("agendaId") agendaId: Long
    ): JsonObject

    // ================================================================
    // 广场相关
    // ================================================================
    @GET(Api.Square.SQUARE_LIST)
    suspend fun getSquareList(
        @Path("pageNo") pageNo: Int
    ): JsonObject

    @GET(Api.Square.SQUARE_USER_LIST)
    suspend fun getUserSquareList(
        @Path("userId") userId: Long,
        @Path("pageNo") pageNo: Int
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @GET(Api.Square.SQUARE_MY_LIST)
    suspend fun getMySquareList(
        @Path("pageNo") pageNo: Int
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Square.DELETE_SQUARE_ARTICLE)
    suspend fun deleteMySquareArticle(
        @Path("articleId") articleId: Long
    ): JsonObject

    @Headers(Header.NEED_LOGIN)
    @POST(Api.Square.ADD_SQUARE_ARTICLE)
    suspend fun addMySquareArticle(
        @Query("title") title: String,
        @Query("link") link: String
    ): JsonObject
}
